package com.mc.designpattern.builder;

import org.apache.commons.lang3.StringUtils;

/**
 * @author fumengchao
 * @ClassName ResourcePoolConfig.java
 * @Description TODO
 * @createTime 2021 0727 09:27:00
 */
public class ResourcePoolConfig {

    private static final int DEFAULT_MAX_TOTAL = 8;
    private static final int DEFAULT_MAX_IDLE = 8;
    private static final int DEFAULT_MIN_IDLE = 0;
    private String name;
    private int maxTotal = DEFAULT_MAX_TOTAL;
    private int maxIdle = DEFAULT_MAX_IDLE;
    private int minIdle = DEFAULT_MIN_IDLE;


    public ResourcePoolConfig(String name) {
        if (StringUtils.isBlank(name))
            throw new IllegalArgumentException();
        this.name = name;
    }


    public void setMaxTotal(int maxTotal) {
        if (maxTotal <= 0) {
            throw new IllegalArgumentException("maxTotal should be positive.");
        }
        this.maxTotal = maxTotal;
    }

    public void setMaxIdle(int maxIdle) {
        if (maxIdle <= 0) {
            throw new IllegalArgumentException("maxTotal should be positive.");
        }
        this.maxIdle = maxIdle;
    }

    public void setMinIdle(int minIdle) {
        if (minIdle <= 0) {
            throw new IllegalArgumentException("maxTotal should be positive.");
        }
        this.minIdle = minIdle;
    }

    public static void main(String[] args) {
        ResourcePoolConfig config = new ResourcePoolConfig("dbconnectionpool");
        config.setMaxIdle(1);
        config.setMaxTotal(2);
        config.setMinIdle(3);
    }
}